﻿using System;

namespace XnaXaml.Graphics
{
    public class Thickness
    {
        public int Left { get; set; }
        public int Top { get; set; }
        public int Right { get; set; }
        public int Bottom { get; set; }

        public static Thickness Default
        {
            get { return new Thickness(1); }
        }

        public Thickness()
        {
            Left = Thickness.Default.Left;
            Top = Thickness.Default.Top;
            Right = Thickness.Default.Right;
            Bottom = Thickness.Default.Bottom;
        }

        public Thickness(int all)
        {
            Left = all;
            Top = all;
            Right = all;
            Bottom = all;
        }

        public Thickness(int leftRight, int topBottom)
        {
            Left = leftRight;
            Top = topBottom;
            Right = leftRight;
            Bottom = topBottom;
        }

        public Thickness(int left, int top, int right, int bottom)
        {
            Left = left;
            Top = top;
            Right = right;
            Bottom = bottom;
        }

        public Thickness(string input)
        {
            var split = input.Split(',');

            if (split.Length <= 1 && split.Length > 0)
            {
                var value = Convert.ToInt32(split[0]);
                Left = value;
                Top = value;
                Right = value;
                Bottom = value;
            }
            if (split.Length == 2)
            {
                var leftRight = Convert.ToInt32(split[0]);
                var topBottom = Convert.ToInt32(split[1]);
                Left = leftRight;
                Top = topBottom;
                Right = leftRight;
                Bottom = topBottom;
            }
            if (split.Length == 4)
            {
                var left = Convert.ToInt32(split[0]);
                var top = Convert.ToInt32(split[1]);
                var right = Convert.ToInt32(split[2]);
                var bottom = Convert.ToInt32(split[3]);
                Left = left;
                Top = top;
                Right = right;
                Bottom = bottom;
            }
        }
    }
}
